home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / .bin / httpd / Solaris_1 / dbdump.pl < prev    next >
Perl Script  |  1996-02-29  |  10KB  |  449 lines

  1. #!/net/pinatubo/opt/PUBperl5/bin/perl5
  2. # /export/scratch/illustra/bin/perl5
  3. # /opt/PUBperl5/bin/perl5
  4. #
  5. # makedesc.pl
  6. #
  7. # Generate The Wais Tree
  8. #
  9. # Copyright Creative Dynamics, Inc. 1995
  10. #
  11. #$dirn = $0;
  12. #$dirn =~ s#(.*)/.*$#$1#;
  13. #require "$dirn/common.pl";
  14.  
  15. $CATDB_NAME = "catalyst";
  16. $USER = "miadmin";
  17.  
  18. #
  19. # use the libmi stuff
  20. #
  21.  
  22. use Mi;
  23.  
  24. $lastCategory = "";
  25. $lastSubCategory = "";
  26. $newchapter = 0;
  27.  
  28. ### Set up output directory
  29.  
  30. $outputdirectory = "/opt/db/wais-src";
  31. umask(022);
  32. mkdir($outputDirectory, 0777);        # make an output directory for book    
  33. chdir "$outputDirectory" || die "Can't cd to $outputDirectory\n";
  34. #unlink(<*>);                # delete all existing files in the output directory
  35.  
  36. {
  37.    local($query,$num_col, @record);
  38.    local($db, $row_desc, $result, $row, $col, $row_num, $error);
  39.  
  40. ### the query
  41.  
  42. $query = "
  43. select  p.Product_id, p.SolCompatible,    
  44.     p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName,
  45.     p.ProdShortDesc, p.ProdLongDesc,
  46.     p.ProdHomePage, p.ProdImage, p.SrcAvail, p.ProdSrcLang,
  47.     p.ProdSpecHand,
  48.     v.VendorAddr1, v.VendorAddr2, v.VendorAddr3, v.VendorCity,
  49.     v.VendorPostCode,
  50.     v.VendorState, v.VendorZip, v.VendorCountry,
  51.     v.VendorPhone1code, v.VendorPhone1,
  52.     v.VendorPhone2code, v.VendorPhone2,
  53.     v.VendorFaxCode, v.VendorFax,
  54.     v.VendorEmailCode, v.VendorEmail,
  55.     v.VendorURL
  56. from   Vendor v using(lock=table),
  57.        Assoc_ProdVend a using(lock=table),
  58.        Products p using(lock=table)
  59. where  a.ProdId = p.Product_id
  60. and    a.VendId = v.Vendor_id
  61. order by p.ProdCatName, p.ProdSubCat, p.ProdName
  62. ;";
  63.  
  64. # where  p.Product_id < 100 -- use to limit
  65. # alternate order: order by p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName
  66.  
  67. ### query the database
  68.  
  69.    ($db = Mi::open("$CATDB_NAME", "$USER", "") ) || die "Can't open Illustra database\n";
  70.  
  71.    (Mi::exec($db, "$query", 0) == 0) || die "Can't exec Illustra query\n";
  72.  
  73.    print "  Query Sent\n";
  74.  
  75.    (($result = Mi::get_result($db)) == 1) || die "Got bad result from Illustra\n";
  76.  
  77.    print "  Got Results\n";
  78.  
  79.    ($row_desc = Mi::get_row_desc_without_row($db)) || die "Error on row description \n";
  80.  
  81.    $num_col = Mi::column_count($row_desc);
  82.  
  83.    print "  Results Have $num_col Columns\n";
  84.  
  85.    $row_num = 0;
  86.    while ($row = Mi::next_row($db, \$error))
  87.    {
  88.     $row_num++;
  89.     print "   Processing row $row_num...\r";
  90.     foreach $col (0..$num_col-1)
  91.     {
  92.           Mi::value($row, $col, $colval, $retlen);
  93.           $record[$col] = $colval;
  94.     }
  95.  
  96. ### Fix the data
  97.  
  98. # map double occurrences of ' to single '
  99.  
  100.     foreach $count (2..12)
  101.     {
  102.         $record[$count] =~ s/\'\'/\'/g;
  103.     }
  104.  
  105. ### Trim trailing spaces
  106.     foreach $count (2..30)
  107.     {
  108.         $record[$count] =~ s/ *$//g;
  109.     }
  110.  
  111. ### Fix descriptions
  112.     $record[7] = ($record[7] =~ /\S/) ? $record[7] : $record[6];
  113.         if ($record[7] eq "")
  114.         {
  115.                 $record[7] = $record[6];
  116.         }
  117.         &makeBullets();
  118.  
  119. ### Now print out the data for this product        
  120.  
  121.     $newchapter = 0;
  122.     if ($lastCategory ne $record[2])
  123.     {
  124.         chdir $outputdirectory || die "bad cd\n";
  125.         $newchapter = 1;
  126.         $outputChapterName = &fix_special($record[2]);
  127.         $outputChapterName = &makefilename($outputChapterName, 25);
  128.         mkdir($outputChapterName, 0777);
  129.         chdir "$outputChapterName" || die "Can't cd to $outputChapterName\n";
  130.         $lastCategory = $record[2];
  131.                 $subTOCname = $outputChapterName . ".html";
  132.                 open(subTOC, "> $subTOCname");
  133.                 &addsubTOCheader($record[2]);
  134.     }
  135.     if ($lastSubCategory ne $record[3])
  136.     {
  137.         if ($record[3] eq "")
  138.         {
  139.             $record[3] = "NoSubcategory";
  140.         }
  141.         if ($newchapter == 0)
  142.         {
  143.             chdir ".." || die "bad sub cd\n";
  144.         }
  145.         $outputSubchapterName = &fix_special($record[3]);
  146.         $outputSubchapterName = &makefilename($outputSubchapterName, 25);
  147.         mkdir($outputSubchapterName, 0777);
  148.         chdir $outputSubchapterName || die "Can't cd to $outputSubchapterName\n";
  149. #        unlink(<*>);
  150.         $lastSubCategory = $record[3];
  151.                 $TOCname = $outputSubchapterName . ".html";
  152.                 open(TOC, "> $TOCname");
  153.                 &makeTOCheader($subTOCname, $record[2], $record[3]);
  154.                 chdir("..") || die "Can't cd to main category";
  155.                 &addsubTOC($record[3], $outputSubchapterName);
  156.                 chdir "$outputSubchapterName" || die "Can't cd to subcategory";
  157.     }
  158.  
  159.     $filename = &fix_special($record[4]);
  160.     $filename = &makefilename($filename, 25);
  161.     $filename .= ".html";
  162.     open(PRODUCT, ">$filename") || die "Can't open product $filename\n";
  163.         &makeproductheader($record[3], $outputChapterName . ".html");
  164.         &makeproduct();
  165.         &makeproducttail();
  166.         &addTOCinfo($filename, $record[4], $record[5]);
  167.         close PRODUCT;
  168.  
  169.     }
  170.  
  171.  
  172. # End of Product
  173.  
  174.    &makeTOCtail();
  175.    close TOC;
  176.    close subTOC;
  177.    Mi::close($db);
  178.  
  179.    print "Processed $row_num records\n";
  180. }
  181.  
  182.  
  183. #------------------------------------------------------------------
  184. # SUBROUTINES
  185. #------------------------------------------------------------------
  186.  
  187. sub makeBullets {
  188.  
  189.     local(@strings) = split(/\n/, $record[7]); 
  190.     local($bullet) = 0; 
  191.  
  192.     foreach $string (@strings)
  193.     {
  194.     if ($string =~ s/^--/<LI>/)
  195.     {
  196.         if ($bullet == 0)
  197.         {
  198.         $string =~ s/<LI>/<UL><LI>/;    
  199.         $bullet = 1;
  200.         }
  201.     }
  202.     else
  203.     {
  204.         if ($bullet == 1)
  205.         {
  206.         $string = "</UL>" . $string;
  207.         $bullet = 0;
  208.         }
  209.     }
  210.     }
  211.     $record[7] = join(/\n/, @strings);
  212.     if ($bullet == 1) # check for corner case
  213.     {
  214.          $record[7] .= "</UL>";
  215.     }
  216. }
  217.  
  218. sub makefilename {
  219.  
  220.         local(@strings) = split(/_/, @_[0]);
  221.     local($length) = @_[1];
  222.         local($new) = "";
  223.     local($first) = 1;
  224.  
  225.     foreach $string (@strings)
  226.     {
  227.     if ($first == 1)
  228.     {
  229.         $new .= $string;
  230.         $first = 0;
  231.     }
  232.     else
  233.     {
  234.         $new .= "_" . $string;
  235.     }
  236.     if (length($new) > $length)
  237.     {
  238.         return $new;
  239.     }
  240.     }
  241.     return $new;
  242. }
  243.  
  244. sub fix_special {
  245.  
  246.     local($text) = @_[0];
  247.  
  248.     $text =~ s/ /_/g;
  249.     $text =~ s/\!/_/g;
  250.     $text =~ s/\*/_/g;
  251.     $text =~ s/\//_/g;
  252.     $text =~ s/\&/_/g;
  253.     $text =~ s/\'/_/g;
  254.     $text =~ s/\`/_/g;
  255.     $text =~ s/#//g;
  256.     return $text;
  257. }
  258.  
  259. #------------------------------------------------------------------
  260. # makeproductheader
  261. #
  262. # subroutine makeproductheader creates header for every product file
  263.  
  264. sub makeproductheader {
  265.  
  266.     local($string) = @_[0];
  267.     local($filename) = @_[1];
  268.  
  269.     print PRODUCT <<PRODUCTHEADER;
  270. <html>
  271. <head>
  272. <title>Solaris - $string</title>
  273. </head>
  274. <body>
  275. <A HREF="http://pinatubo/test.html"><IMG SRC="/goto_toc.gif"> Catalyst Catalog Search Page</A> <A HREF=../$filename><IMG SRC="/goto_back.gif"> Sub-category</A>
  276. <HR>
  277. <H2><A NAME=$record[3]>"$record[3]"</A></H2>
  278.  
  279. <HR>
  280. PRODUCTHEADER
  281. }
  282.  
  283. #------------------------------------------------------------------
  284. # makeproduct
  285. #
  286. # subroutine makeproduct creates info for every product file
  287.  
  288. sub makeproduct {
  289.  
  290.     local($source) = "No";
  291.     local($address) = $record[13] . " " . $record[14] . " " . $record[15];
  292.     local($address1) = $record[16] . ", " . $record[17] . $record[18] . " " . $record[19];
  293.     local($spec) = $record[12];
  294.     local($phone) = "";
  295.     local($phone1) = "";
  296.     local($fax) = "";
  297.     local($email) = "";
  298.     local($url) = "";
  299.     local($language) = "";
  300.     if ($record[11] ne "")
  301.     {
  302.     $language = "Language: " . $record[11] . "<BR>";
  303.     }
  304.     if ($record[22] ne "")
  305.     {
  306.         $phone = "Phone:  " . $record[21] . $record[22];
  307.         $phone1 = $record[23] . $record[24];
  308.     }
  309.     if ($record[26] ne "")
  310.     {
  311.         $fax = "Fax:    " . $record[25] . $record[26];
  312.     }
  313.     if ($record[28] ne "")
  314.     {
  315.         $email = "Email:  " . $record[27] . $record[28];
  316.     }
  317.     if ($record[29] ne "")
  318.     {
  319.         $url = "Url:    " . $record[29];
  320.     }
  321.     $address =~ s/^//g;
  322.     $address1 =~ s/^//g;
  323.     $spec =~ s/\[//g;
  324.     $spec =~ s/]//g;
  325.     $spec =~ s/^ * //g;
  326.     $spec =~ s/^,//g;
  327.     if ($spec eq "")
  328.     {
  329.         $spec = "None.";
  330.     }
  331.  
  332.     if ($phone1 ne "")
  333.     {
  334.         $phone .= "\n        " . $phone1;
  335.     }
  336.  
  337.     if ($record[10] eq "t" or $record[10] eq "T")
  338.     {
  339.         $source = "Yes";
  340.     }
  341.     print PRODUCT <<MAKEPRODUCT
  342. <H3><A NAME=$record[4]>$record[4]</A></H3>
  343. <H4><A NAME=$record[5]>$record[5]</A></H4>
  344. $record[7]<p>
  345. $language
  346. Source Avail: $source<BR>
  347. Product Special Handling: $spec<BR>
  348. <HR>
  349. <PRE>
  350. <B>$record[5]</B>
  351. $address
  352. $address1
  353. $record[20]<HR>
  354. $phone
  355. $fax
  356. $email
  357. $url
  358. </PRE>
  359. MAKEPRODUCT
  360. }
  361.  
  362. #------------------------------------------------------------------
  363. # makeproducttail
  364. #
  365. # subroutine makeproducttail creates tail for product file
  366.  
  367. sub makeproducttail {
  368.  
  369.     print PRODUCT <<MAKEPRODUCTTAIL
  370. </body>
  371. </html>
  372. MAKEPRODUCTTAIL
  373. }
  374.  
  375. #------------------------------------------------------------------
  376. # makeTOCheader
  377. #
  378. # subroutine MakeTOCheader prints header for each TOC
  379.  
  380. sub makeTOCheader {
  381.  
  382.     local($filename) = @_[0];
  383.     local($category) = @_[1];
  384.     local($subcategory) = @_[2];
  385.  
  386.     print TOC <<makeTOCheader
  387. <html>
  388. <title>Solaris - <A HREF="$filename">$subcategory</A> Products</title>
  389.  
  390. <A HREF="http://pinatubo/test.html"><IMG SRC="/goto_toc.gif"> Catalyst Catalog Search Page </A>
  391. <A HREF="../$filename"><IMG SRC="/goto_back.gif"> Sub-category</A>
  392. <HR>
  393. <H1>Catalyst Solaris Products</H1>
  394. <H2>Product Listing</H2>
  395. <HR>
  396.  <h2><IMG SRC="/bullet_ball_red.gif"> <A HREF="../$filename">$subcategory</A></h2>
  397. <ul>
  398. makeTOCheader
  399. }
  400.  
  401. sub addsubTOCheader {
  402.  
  403.     local($category) = @_[0];
  404.  
  405.     print subTOC <<addsubTOCheader
  406. <title>Solaris - Networking</title>
  407.  
  408. <A HREF="http://pinatubo/test.html"><IMG SRC="/goto_toc.gif"> Catalyst Catalog Search Page</A>
  409. <HR>
  410. <H1>Catalyst Solaris Products</H1>
  411. <H2>Sub-categories</H2>
  412. <HR>
  413. <H2><IMG SRC="/bullet_ball_blue.gif"> $category<H2>
  414. <UL>
  415. addsubTOCheader
  416.  
  417. }
  418.  
  419. sub makeTOCtail {
  420.  
  421.     print subTOC <<makeTOCtail
  422. </ul></html>
  423. makeTOCtail
  424. }
  425.  
  426. sub addsubTOC {
  427.  
  428.     local($subcategory) = @_[0];
  429.     local($subcategoryname) = @_[1];
  430.  
  431.     print subTOC <<addsubTOC
  432. <IMG SRC="/bullet_ball_red.gif"><A HREF="$subcategoryname/$subcategoryname.html"><STRONG>  $subcategory</A></STRONG></A><BR>
  433. addsubTOC
  434. }
  435.  
  436. sub addTOCinfo {
  437.  
  438.         local($filename) = @_[0];
  439.         local($product) = @_[1];
  440.         local($vendor) = @_[2];
  441.  
  442.     print TOC <<addTOCinfo
  443. <B>
  444. <IMG SRC="/bullet_ball_yellow.gif"> <A HREF="$filename">$product</A></B>
  445. <ul>
  446. $vendor</ul><p>
  447. addTOCinfo
  448. }
  449.